package cc.lucien.map;

import java.util.*;

public class MapDemo01 {
    public static void main(String[] args) {
        Map<String,String> teacher = new HashMap<>();
        Map<String,Integer> score = new HashMap<>();
        List<Map<String,String>> list = new ArrayList<>();
        // 存数据
        teacher.put("C语言", "许老师");
        score.put("C语言", 76);
        teacher.put("Java", "蔡老师");
        score.put("Java", 86);
        list.add(teacher);

        // 遍历
        System.out.println("课程名\t老师\t\t成绩");
        for (Map<String, String> map : list) {
            Set<Map.Entry<String, String>> set = map.entrySet();
            for (Map.Entry<String, String> entry : set) {
                System.out.println(entry.getKey()+"\t"+entry.getValue()+"\t"+score.get(entry.getKey()));
            }
        }

        test();
    }

    public static void test(){
        Map<String,Object> map1 = new HashMap<>();
        map1.put("course", "Java");
        map1.put("teacher", "许老师");
        map1.put("score", 89);

        Map<String,Object> map2 = new HashMap<>();
        map2.put("course", "C#");
        map2.put("teacher", "叶老师");
        map2.put("score", 79);

        Map<String,Object> map3 = new HashMap<>();
        map3.put("course", "JSP");
        map3.put("teacher", "蔡老师");
        map3.put("score", 91);

        List<Map<String,Object>> list = new ArrayList<>();
        list.add(map1);
        list.add(map2);
        list.add(map3);

        for (Map<String, Object> map : list) {
            System.out.println("course：" + map.get("course"));
        }
    }
}
